import { defineStore } from "pinia"
import { ref } from "vue"
import { asyncComputed } from "@vueuse/core"
import api from "@/api"

export const useBasicInfoStore = defineStore("basicInfo", () => {

  const eqpos = [
    { id: 1, type: "left", label: "上衣", top: 10, left: 47 },
    { id: 2, type: "left", label: "下装", top: 57, left: 0 },
    { id: 3, type: "left", label: "头肩", top: 10, left: 0 },
    { id: 4, type: "left", label: "腰带", top: 57, left: 47 },
    { id: 5, type: "left", label: "鞋", top: 104, left: 0 },
    { id: 6, type: "right", label: "手镯", top: 57, left: 47 },
    { id: 7, type: "right", label: "项链", top: 57, left: 0 },
    { id: 8, type: "right", label: "戒指", top: 104, left: 0 },
    // { id: 9, type: "right", label: "辅助装备", top: 104, left: 47 },
    // { id: 10, type: "right", label: "魔法石", top: 151, left: 0 },
    // { id: 11, type: "right", label: "耳环", top: 151, left: 47 },
    { id: 12, type: "right", label: "武器", top: 10, left: 47 },
    { id: 13, type: "right", label: "称号", top: 10, left: 0 },
    // { id: 14, type: 'right', label: '副武器', top: 5, left: 87 },
    // { id: 15, type: 'left', label: '辟邪玉', top: 151, left: 47 },
    { id: 16, type: "left", label: "宠物", top: 104, left: 47 }
  ]

  const adventure = asyncComputed(async () => {
    const res = await api.adventures().then(r => r.data)
    const list: any[] = []
    let count = 0
    res.forEach((job) => {
      const jobInfo: {
        text: string
        value: string
        children?: any[]
        material:string []
      } = {
        text: job.title,
        // value:job.name
        value: job.name,
        children: [],
        material: []
      }
      job.children.forEach((child) => {
          count += 1
          jobInfo.children?.push({
            text: child.title,
            value: child.options && child.options.length > 1 ? count : child.options[0].class,
            material: child.material,
            children: child.options.length > 1 ? child.options?.map(a => {
              return {
                text: `${child.title}(${a.title})`,
                value: a.class
              }
            }) : []
          })

      })
      list.push(jobInfo)
    })
    return list
  })


  const currentRole = ref("GF.mage_female.elementalist")

  return {
    eqpos,
    adventure,
    currentRole
  }
})
